package com.elegantsoft.pakistannews;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.MenuItem;
import com.atiffarrukh.pakistannews.R;

import com.elegantsoft.pakistannews.rssfeed.MessageList;
import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.google.analytics.tracking.android.EasyTracker;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

public class WebViewT extends SherlockActivity{
	Bundle webid;
	WebView myWebView;
	
	// Progress Dialog
	ProgressBar progressBar;
	TextView tv;
	
	Bundle b;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.web_view);
		
		AdView adView = (AdView)this.findViewById(R.id.adView);
	    adView.loadAd(new AdRequest());
		
		b = getIntent().getExtras();
		
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		progressBar = (ProgressBar) findViewById(R.id.progressBar);
		tv = (TextView) findViewById(R.id.tvc);
		myWebView = (WebView) findViewById(R.id.webview);
		myWebView.setWebViewClient(new WebViewClient(){
			@Override
		    public boolean shouldOverrideUrlLoading(WebView view, String url){
		      view.loadUrl(url);
		      return true;
		    }
			 @Override
		        public void onLoadResource(WebView  view, String  url){
				 
		        }
			  @Override
		        public void onPageFinished(WebView view, String url) {
		            // TODO Auto-generated method stub
		            super.onPageFinished(view, url);
		 
		            progressBar.setVisibility(View.GONE);
		            tv.setVisibility(View.GONE);
		        }
			 
		});
		
		webid = getIntent().getExtras();
		myWebView.getSettings().setJavaScriptEnabled(true);
		Log.d("Uri", "" + webid.getString("website"));
		myWebView.loadUrl(webid.getString("website").toString());
		
	}
	
	class LoadingSite extends  AsyncTask<String, String, String>{
		@Override
		protected void onPreExecute() {
			// TODO Auto-generated method stub
			super.onPreExecute();
			/*pDialog = new ProgressDialog(WebViewT.this);
			pDialog.setMessage("Loading Feeds...");
			pDialog.setIndeterminate(false);
			pDialog.setCancelable(false);
			pDialog.show();*/
			
		}
		@Override
		protected String doInBackground(String... params) {
			// TODO Auto-generated method stub
			
			return null;
		}
		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			//updateListUI();
			//pDialog.dismiss();
			
			
		}
		
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		
			// TODO Auto-generated method stub
			switch (item.getItemId()) {

			case android.R.id.home:
				// app icon in action bar clicked; go home
				Intent intentHome = new Intent(this, MessageList.class);
				intentHome.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				intentHome.putExtra("category", b.getString("category"));
				intentHome.putExtra("channelName", b.getString("channelName"));
				intentHome.putExtra("alternate", b.getBoolean("alternate"));
				intentHome.putExtra("english", b.getBoolean("english"));
				startActivity(intentHome);
				return true;

			default:
				return super.onOptionsItemSelected(item);
		}
	}
	 @Override
	  public void onStart() {
	    super.onStart();
	  
	   // EasyTracker.getInstance().activityStart(this); // Google Analytics.
	  }

	  @Override
	  public void onStop() {
	    super.onStop();
	    
	   // EasyTracker.getInstance().activityStop(this); // Google Analytics.
	  }
	

}
